package im.starchat.chat;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * Created by liuchao on 3/16/16.
 */
public class Test {

    public static void main(String[] args){
        Calendar calendarNow = Calendar.getInstance();
        System.out.println("时间:" + calendarNow.getTime());
//        formatStringToDate("2016-03-10T11:05:26.246+08:00");
//        javax.xml.bind.DatatypeConverter.parseDateTime("2010-01-01T12:00:00Z")
    }

    /**
     * 字符串转时间 要求字符串格式(2011-01-05)
     */
    public static void formatStringToDate(String dateString) {
        //2016-03-10T11:05:26.246+08:00
        //yyyy-MM-dd'T'HH:mm:ss.SSSZ
        SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
//        SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSS+Z");
        try {
            Date date = sFormat.parse(dateString);
            System.out.println("字符串转时间:" + date);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
